home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / GAPLib.lha / GAPLib / utility / ReportExample.c < prev   
Encoding:
C/C++ Source or Header  |  1999-04-23  |  1.4 KB  |  70 lines

  1. /*
  2.  * Modified Minimal Example Function Optimization.
  3.  *
  4.  * This example has been modified to show the useage of
  5.  * the report generation utility code accompanying GAP-Lib.
  6.  */
  7.  
  8. #include <time.h>
  9. #include <stdio.h>
  10. #include <GAP.h>
  11.  
  12. #include "report.h"
  13.  
  14. /* The representation of the individuals. */
  15.  
  16. struct Polyphant {
  17.    unsigned char  v;
  18. };
  19.  
  20. double fitfunc(struct Polyphant *);
  21.  
  22. int main(void)
  23. {
  24. struct Population *Pop;
  25. struct Report *Rep;
  26. int i,n;
  27.  
  28. struct TagItem RepTags[] = {
  29.     {REP_Multipass,TRUE},    /* Generate averages from several runs. */
  30.     {REP_Generations,25},    /* 25 generations in each run.  */
  31.     {TAG_DONE,0L}
  32. };
  33.  
  34. struct TagItem EvolveTags[] = {
  35.     {EVL_Evaluator,(IPTR)fitfunc},
  36.     {TAG_DONE,0L}
  37. };
  38.  
  39. EnterGAP(2); /* Initialize environment. */
  40. InitRand(time(NULL));   /* Initialize random number generator. */
  41.  
  42. Rep = MakeReport("Example",RepTags);    /* Create a report structure. */
  43.  
  44. for(n=0;n!=8;n++) {    /* Perform 8 runs of this GA. */
  45.  
  46.     Pop = CreatePopulation(20,sizeof(struct Polyphant),NULL); /* Create a population. */
  47.  
  48.     if(Pop!=NULL) {
  49.        printf("Run %d, created %ld individuals.\n",n,Pop->NumPolys);
  50.        for(i=0;i!=25;i++) { /* Evolve 25 generations. */
  51.           Pop = Evolve(Pop,EvolveTags);
  52.             DoReport(Rep,Pop,AVERAGE|MAX);
  53.        }
  54.        DeletePopulation(Pop);
  55.  
  56.     } else {
  57.        fprintf(stderr,"Unable to create population.\n");
  58.     }
  59. }
  60.  
  61. EndReport(Rep);
  62.  
  63. return(0);
  64. }
  65.  
  66. double fitfunc(struct Polyphant *p)
  67. {
  68. return((double)p->v);
  69. }
  70.